<?php

class cntrlimageset implements viewController {
	private $area;
	private $side;
	private $dependencies = array("JavaScript" => array("facebox.js", "imageset.js"), "CSS" => array("facebox.css") );
	private $pageName = "PicBoard Photo Albums - ";
	private $userObj;
	private $tools;
	private $isID;


	public function __construct(user &$userObj){
		$this->userObj = $userObj;
		if($this->userObj->getAccessLevel() == -1 || $this->userObj->getAccessLevel() == ""){
			header("Location: home");
		} else {
			
			$this->area = new template('area.listPage');	
			$this->side = new template('control.imageSide');
			$this->tools = new template('toolset.imageset');
			
			parse_str( $_GET['act'] );
			
			if(isset($id)){
				$this->isID = $id;
				
				$imageData = images::getListImages($this->isID);
						
				if(count($imageData) > 0){
					
					$images = $this->formatImagesAndReturn(new template('fragment.imageListItem'), $imageData );
									
					$this->pageName .= $imageData[0]['setName'];	
				} else {
					$images = "";
				}		
				
				$this->area->replaceAll(array(
					'list' => $images,
					'pagination' =>	"",
					'pageNav' => ""
				));	
			
			} else {
				header("Location: home");
			}
		}
	}

	private function formatImagesAndReturn(template &$imageTemplate, $images){
		$imageOutput = "";
				
		foreach($images as $image){
						
			$imageTemplate->replace("image", $image['imageURL']);
			$imageTemplate->replace("name", $image['name']);
			$imageTemplate->replace("id", $image['imgID']);
			$imageOutput .= $imageTemplate->get();
			$imageTemplate->reset();
		}	
		return $imageOutput;			
	}

	public function getSide(){
		return $this->side;
	}
	
	public function getArea(){
		return $this->area;
	}
	
	public function getDependencies(){
		return $this->dependencies;
	}

	public function getPageName(){
		return $this->pageName;
	}
	
	public function getTools(){
		return $this->tools;
	}	

}

?>